<template>
	<view>
		<nav-back></nav-back>
		
		<view class="title">
		  <text>您的微信号 </text> 
		</view>
		<view class="tip">未经您的允许微信号不会对外公布</view>
		
		<view class="nickname">
		  <view class="my-input" >
			<input class="uni-input" :value="wxnumber" :disabled="isPhone" @input="handleWxnumber" placeholder="请输入微信号" />
		  </view>
		  <view class="treaty">
		    <view class="agree" @click="handlePhone">
		      <image v-if="isPhone==false" src="/static/img/agree1.png" mode=""/>
		      <image v-if="isPhone==true" src="/static/img/agree2.png" mode=""/>
		    </view>
		    我的手机号就是微信号
		  </view>
		</view>
		
		<button class="next" type="primary" @click="handleNext">完成</button>

	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import NavBack from '@/components/NavBack.vue'

	export default {
		components: {
			NavBack
		},
		data() {
			return {
				isPhone:false,
				wxnumber:''
			}
		},
		methods: {
			handleWxnumber(e){
				console.log(e.detail.value, 'handleName');
				this.wxnumber = e.detail.value
			  },
			  handlePhone(){
			    this.isPhone = !this.isPhone
			    if(this.isPhone){
			      this.wxnumber = uni.getStorageSync('userName')||''
			    }else{
			      this.wxnumber = ''
			    }
			  },
			  handleNext(){
			    if(!this.wxnumber){
			      uni.showToast({
			        title: '请填写微信号',
			        icon: 'none',
			        duration: 2000
			      })
			      return
			    }
			    getApp().globalData.userInfo.wechatNumber = this.wxnumber
			    console.log(this.wxnumber,'this.wxnumber');
			
			    request(`/employee/insertBaseInfo`,{
			      method:'POST',
			      data:getApp().globalData.userInfo
			    }).then(((res)=>{
			      console.log(res.data,'res');
			      if(res.data.code==1){
					  uni.showToast({
						title: '提交成功',
						icon: 'none',
						duration: 2000
					  })
			        uni.navigateTo({
			          url: '/pages/userInfo/successInfo/successInfo'
			        })
					uni.setStorageSync('avatar', getApp().globalData.userInfo.avatar)
					uni.setStorageSync('name', getApp().globalData.userInfo.name)
			      }else{
					uni.showToast({
						title: res.data.msg,
						icon: 'none',
						duration: 2000
					})
			      }
			    }))
			
			  },
		}
	}
</script>

<style lang="scss">
	@import "@/style/register.scss";

.tip{
  display: flex;
  align-items: center;
  margin-top: 20rpx;
  image{
    width: 32rpx;
    height: 32rpx;
    margin:0 10rpx;
  }
}

.nickname{
  margin-top: 200rpx;
  .my-input{
    border-radius: 20rpx;
  }
}
.treaty{
  width: 100%;
  justify-content: start;
}
</style>
